function throttle(func: (...args: any[]) => void, delay: number): (...args: any[]) => void {
  let timeoutId: NodeJS.Timeout | null;
  let lastExecTime = 0;

  return function (...args: any[]): void {
    const currentTime = Date.now();

    if (currentTime - lastExecTime >= delay) {
      func.apply(this, args);
      lastExecTime = currentTime;
    } else {
      if (timeoutId) {
        clearTimeout(timeoutId);
      }

      timeoutId = setTimeout(() => {
        func.apply(this, args);
        lastExecTime = Date.now();
      }, delay - (currentTime - lastExecTime));
    }
  };
}
export default throttle